package com.logistics.modules.vehicleManagement.service.impl;

import cn.hutool.core.convert.Convert;
import com.logistics.modules.vehicleManagement.service.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.logistics.common.utils.PageUtils;
import com.logistics.common.utils.Query;

import com.logistics.modules.vehicleManagement.dao.VehicletypeDao;
import com.logistics.modules.vehicleManagement.entity.VehicletypeEntity;
import com.logistics.modules.vehicleManagement.service.VehicletypeService;
import org.springframework.transaction.annotation.Transactional;


/**
 * impl vehicletype服务
 *
 * @author 水穷处云起时
 * @date 2022/06/03
 */
@Service("vehicletypeService")
public class VehicletypeServiceImpl extends ServiceImpl<VehicletypeDao, VehicletypeEntity> implements VehicletypeService {

    @Autowired
    private VehicleService vehicleService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        String name = Convert.toStr(params.get("name"));

        IPage<VehicletypeEntity> page = this.page(
                new Query<VehicletypeEntity>().getPage(params),
                new QueryWrapper<VehicletypeEntity>()
                .like(name != null && name != "", "Vehicle_Type" , "%" + name + "%")
        );

        return new PageUtils(page);
    }

    @Override
    public List<VehicletypeEntity> selectAll() {
        return this.baseMapper.selectList(null);
    }

    /**
     * 删除由ids
     *
     * @param asList 正如列表
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void deleteByIds(List<Integer> asList) {
        // 1. 进行删除校验
        vehicleService.deleteCheck(asList);
        // 2. 删除
        this.baseMapper.deleteBatchIds(asList);
    }

}